{/*
* Author: Kevin
* Contact: 858785716@qq.com
* Github: https://github.com/xs47968224/MVC-form-field-loader
* Description: 用于循环输出表单字段，在controller中定义edit_fields数组即可
*/ }
<div class="row">
{foreach name="data.edit_fields" item="field" key="key" }
	{switch name=$field['type'] }
        {case value="text"}
            {if isset($field['extra']['wrapper'])}
                <div class="<?php echo $field['extra']['wrapper'];?>">
            {else/}
                <div class="col-xs-12">
            {/if}
                <div class="form-group">
                    {if isset($field['label']) AND $field['label']}<label>{$field['label']}</label>{/if}

                    <input type="{$field['type']}"
                        {if isset($field['id']) AND $field['id']}id="{$field['id']}"{/if}
                        {if isset($field['disabled']) AND $field['disabled']}disabled="disabled"{/if}
                        class="form-control {if isset($field['class']) AND $field['class']}{$field['class']}{/if}"
                        {if isset($field['extra']['data']['format']) }data-format="{$field['extra']['data']['format']}"{/if}
                        name="{$key}" value="{if isset($item[$key])}{$item[$key]}{/if}">

                    {if isset($field['notes']) AND $field['notes']}<p class="help-block">{$field['notes']}</p>{/if}
                </div>
            </div>
        {/case}
        {case value="password"}
            {if isset($field['extra']['wrapper'])}
                <div class="<?php echo $field['extra']['wrapper'];?>">
            {else/}
                <div class="col-xs-12">
            {/if}
                <div class="form-group">
                    {if isset($field['label']) AND $field['label']}<label>{$field['label']}</label>{/if}

                    <input type="{$field['type']}"
                    {if isset($field['id']) AND $field['id']}id="{$field['id']}"{/if}
                    {if isset($field['disabled']) AND $field['disabled']}disabled="disabled"{/if}
                    class="form-control" name="{$key}" value="">

                    {if isset($field['notes']) AND $field['notes']}<p class="help-block">{$field['notes']}</p>{/if}
                </div>
            </div>
        {/case}
        {case value="file"}
            {if isset($field['extra']['wrapper'])}
                <div class="<?php echo $field['extra']['wrapper'];?>">
            {else/}
                <div class="col-xs-12">
            {/if}
                <div class="form-group">
                    {if isset($field['label']) AND $field['label']}<label>{$field['label']}</label>{/if}

                    <input type="{$field['type']}"
                        {if isset($field['id']) AND $field['id']}id="{$field['id']}"{/if}
                        {if isset($field['disabled']) AND $field['disabled']}disabled="disabled"{/if}
                        name="{$key}">

                    {if isset($item[$key]) AND $item[$key] != ""}
                        <a href="__UPLOADS__/{$item[$key]}" target="_blank"><img src="__UPLOADS__/{$item[$key]}" class="img-responsive img-thumbnail"></a>
                        <a href="{:url($data.module_url . 'delete_image/' . $item['id'])}" class="btn btn-danger"><i class="glyphicon glyphicon-trash"></i> Delete</a>
                    {/if}

                    {if isset($field['notes']) AND $field['notes']}<p class="help-block">{$field['notes']}</p>{/if}
                </div>
            </div>
        {/case}
        {case value="radio"}
            {if isset($field['extra']['wrapper'])}
                <div class="<?php echo $field['extra']['wrapper'];?>">
            {else/}
                <div class="col-xs-12">
            {/if}
                <div class="checkbox">
                    {if isset($field['label']) AND $field['label']}<span>{$field['label']}</span>{/if}

                    {foreach $field['default'] as $ov => $ol }
                        <label>
                            <input type="{$field['type']}" name="{$key}"
                                {if isset($field['disabled']) AND $field['disabled']}disabled="disabled"{/if}
                                value="{$ov}" {if(isset($item[$key]) && $item[$key] == $ol)}
                                checked="checked" {/if}> {$ol}
                        </label>
                    {/foreach}

                    {if isset($field['notes']) AND $field['notes']}<p class="help-block">{$field['notes']}</p>{/if}
                </div>
            </div>
        {/case}
        {case value="checkbox"}
            {if isset($field['extra']['wrapper'])}
                <div class="<?php echo $field['extra']['wrapper'];?>">
            {else/}
                <div class="col-xs-12">
            {/if}
                <div class="checkbox">
                    {if isset($field['label']) AND $field['label']}<span>{$field['label']}</span>{/if}

                    {foreach $field['default'] as $ov => $ol }
                        <label>
                            <input type="{$field['type']}" name="{$key}[]"
                                {if isset($field['disabled']) AND $field['disabled']}disabled="disabled"{/if}
                                value="{$ov}" {if(isset($item[$key]) && $item[$key] == $ol)}
                                checked="checked" {/if}> {$ol}
                        </label>
                    {/foreach}

                    {if isset($field['notes']) AND $field['notes']}<p class="help-block">{$field['notes']}</p>{/if}
                </div>
            </div>
        {/case}
        {case value="select"}
            {if isset($field['extra']['wrapper'])}
                <div class="<?php echo $field['extra']['wrapper'];?>">
            {else/}
                <div class="col-xs-12">
            {/if}
                <div class="form-group">
                    {if isset($field['label']) AND $field['label']}<label>{$field['label']}</label>{/if}

                    <select  name="{$key}"
                        {if isset($field['id']) AND $field['id']}id="{$field['id']}"{/if}
                        {if isset($field['disabled']) AND $field['disabled']}disabled="disabled"{/if}
                        class="form-control" style="max-width: 300px;">

                            {foreach $field['default'] as $ov => $ol }
                                <option value="{$ov}" {if isset($item[$key]) AND $item[$key] == $ol}selected="selected"{/if}>{$ol}</option>
                            {/foreach}
                    </select>

                    {if isset($field['notes']) AND $field['notes']}<p class="help-block">{$field['notes']}</p>{/if}
                </div>
            </div>
        {/case}
        {case value="textarea"}
            {if isset($field['extra']['wrapper'])}
                <div class="<?php echo $field['extra']['wrapper'];?>">
            {else/}
                <div class="col-xs-12">
            {/if}
                <div class="form-group">
                    {if isset($field['label']) AND $field['label']}<label>{$field['label']}</label>{/if}

                    <textarea
                        class="form-control {if isset($field['class']) AND $field['class']}{$field['class']}{/if}"
                        {if isset($field['id']) AND $field['id']}id="{$field['id']}"{/if}
                        name="{$key}"
                        {if isset($field['disabled']) AND $field['disabled']}disabled="disabled"{/if}>{if isset($item[$key]) AND $item[$key]}{$item[$key]}{/if}</textarea>
                    {if(isset($data.ckeditor) and $data.ckeditor)}{:display_ckeditor($data.ckeditor);}{/if}

                    {if isset($field['notes']) AND $field['notes']}<p class="help-block">{$field['notes']}</p>{/if}
                </div>
            </div>
        {/case}

        {case value="alert"}
            {if isset($field['extra']['wrapper'])}
                <div class="<?php echo $field['extra']['wrapper'];?>">
            {else/}
                <div class="col-xs-12">
            {/if}
                <div class="alert {if isset($field['class']) AND $field['class']}{$field['class']}{else/}alert-info{/if}">
                    {if isset($field['default'])}{$field['default']}{/if}
                </div>
            </div>
        {/case}

        {case value="hr"}
             <div class="clearfix hr b-b mb-20 pb-20"></div>
        {/case}

        {case value="clearfix"}
             <div class="clearfix"></div>
        {/case}
        {default /}
    {/switch}
{/foreach}
</div>